/**
 * Created by loso on 2017/3/23.
 */
public class _190_ReverseBits {

    public static void main(String[] args) {
        _190_ReverseBits a = new _190_ReverseBits();
        int b = a.reverseBits(2);
        System.out.println(b);
        System.out.println("a = " + Integer.toBinaryString(2));
        System.out.println("b = " + Integer.toBinaryString(b));
    }

    public int reverseBits(int n) {
        int out = 0;
        int bit1 = 0b1;
        int bit2 = 0x80000000;
        for (int i = 0; i < 32; i++) {
            out += (n & bit1) == 0? 0:bit2;
            bit1 = bit1 << 1;
            bit2 = bit2>>>1;
        }
        return out;
    }
}
